package com.example.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.pojo.PageData;
import com.example.pojo.ResultBean;
import com.example.service.IWorkOrderService;
import com.example.vo.WorkOrderDetailVo;
import com.example.vo.WorkOrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lyj
 * @since 2023-02-20
 */
@RestController
@RequestMapping("/work-order")
public class WorkOrderController {
    @Autowired
    private IWorkOrderService workOrderService;

    /**
     * 条件分页查询
     * @param pageData
     * @param map
     * @return
     */
    @GetMapping("list")
    public ResultBean list(PageData pageData, @RequestParam Map<String, Object> map) {
        map.forEach((k, v) -> System.out.println(k + ":" + v));

        Page<WorkOrderVo> page = new Page<>(pageData.getPageNum(),pageData.getPageSize());
        workOrderService.queryByCondition(page,map);
        return ResultBean.success(page);
    }

    /**
     * 根据工单code获取工单详细信息以及关联危废品详情和转运记录
     * @param code
     * @return
     */
    @GetMapping("/workOrderDetail/{code}")
    public ResultBean workOrderDetail(@PathVariable("code") String code){
        System.out.println("获取工单详情的编码：" + code);
        WorkOrderDetailVo workOrderDetailVo = workOrderService.queryWorkOrderDetailByWorkOrderCode(code);
        return ResultBean.success(workOrderDetailVo);
    }

}
